<html>

<head>
    <title>保存、编译和运行Java应用</title>
</head>

<body>
    <table width=100%>
        <tr>
            <td align=left>
                <a href="static.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=bottom border=0
                        alt="Previous | "></a><a href="../nutsandbolts/index.html"><img src=../../images/NextArrow.gif
                        width=26 height=26 align=bottom border=0 alt="Next | "></a><a href="../../index.html"><img
                        src=../../images/WayUpArrow.gif width=26 height=26 align=bottom border=0
                        alt="Trail Map | "></a><a href="../index.html"><img src=../../images/javaHeader.gif width=26
                        height=26 align=bottom border=0 alt="Writing Java Programs | "></a>
            <td>
            <td align=right>
                <a href="index.html"><strong><em>Java应用程序剖析</em></strong></a>
            </td>
        </tr>
    </table>
    <p>
        <hr size=4>

    <h2>
        保存、编译和运行Java应用
    </h2>
    <p>
    <blockquote>
        按照以下步骤保存、编译和运行Java程序。这些说明仅提供编译和运行本课程示例程序所需的最少信息。有关编译器、解释器以及构建和管理编程环境的更多信息，请参阅
        <a href="../../tools/index.html"><em>java开发环境</em></a>
        <a href="../../tools/index.html"><img src=../../images/toolIcon.gif width=20 height=20 border=0></a>.

        <h4>保存程序</h4>
        <blockquote>
            You can use any editor or word processing program
            to create and edit a Java program,
            as long as it can save files in ASCII format.
            Java programs must be saved in a file whose
            name ends with the <code>.java</code> extension, so
            using your favorite ASCII editor, enter the program
            exactly as it appears on the <a href=index.html>first page</a>
            of this lesson and save the program to a file named
            <code>DateApp.java</code>.
        </blockquote>

        <h4>Compiling a Java Program</h4>
        <blockquote>
            Having created your Java program, you must <a href=_compiling.html>compile your program</a>
            using the Java compiler before can you run it.
            If you have any problems, see
            <a href=../../troubleshooting/compilerproblems.html>Troubleshooting Compiler Problems</a>
            <a href=../../troubleshooting/compilerproblems.html><img src=../../images/troubleIcon.gif width=20 height=20
                    border=0></a>.

            <p>
                The Java compiler translates Java source code into <em>Java bytecodes</em>
                which are components of a machine-level language for the <em>Java virtual machine</em>.
                Java bytecodes are interpreted and executed by the Java interpreter.
            <p>
                When you compile a Java source file, the compiler
                creates a file with the <code>.class</code> extension
                in the same folder as the source file.
                The compiler names the resulting <code>.class</code>
                file after the class defined in the source file.
                For example, when you compile the <code>DateApp</code> class you created
                above, the compiler names the resulting class file <code>DateApp.class</code>
                after the class, regardless of the name of the source file.
                Even if you were to save the <code>DateApp</code> class to a source
                file named <code>Wow.java</code>, the compiler
                would still create a file named <code>DateApp.class</code>.
                By convention, to alleviate confusion, Java source files are named for the class defined within.
        </blockquote>

        <h4>Running a Java Application</h4>
        <blockquote>
            Now, you can <a href=_interpreting.html>run your application</a> using the Java interpreter.
            The program should display the current date and time.
            If you have any problems, see
            <a href=../../troubleshooting/interpreterproblems.html>Troubleshooting Interpreter Problems</a>
            <a href=../../troubleshooting/interpreterproblems.html><img src=../../images/troubleIcon.gif width=20
                    height=20 border=0></a>.
        </blockquote>

        <h4>See Also</h4>
        <blockquote>
            <a href=http://java.sun.com/JDK-beta/tools/solaris/javac.html><img src=../../images/manPagesIcon.gif width=8
                    height=20 border=0></a>
            <a href=http://java.sun.com/JDK-beta/tools/solaris/javac.html>Compiler Man Page</a><br>
            <a href=http://java.sun.com/JDK-beta/tools/solaris/java.html><img src=../../images/manPagesIcon.gif width=8
                    height=20 border=0></a>
            <a href=http://java.sun.com/JDK-beta/tools/solaris/java.html>Interpreter Man Page</a>
        </blockquote>

    </blockquote>
    <p>
        <hr size=4>
    <p>
    <table width=100%>
        <tr>
            <td align=left>
                <a href="static.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=top border=0
                        alt="Previous | "></a><a href="../nutsandbolts/index.html"><img src=../../images/NextArrow.gif
                        width=26 height=26 align=top border=0 alt="Next | "></a><a href="../../index.html"><img
                        src=../../images/WayUpArrow.gif width=26 height=26 align=top border=0 alt="Trail Map | "></a><a
                    href="../index.html"><img src=../../images/javaHeader.gif width=26 height=26 align=top border=0
                        alt="Writing Java Programs | "></a>
            <td>
            <td align=right>
                <a href="index.html"><strong><em>Java应用程序剖析</em></strong></a>
            </td>
        </tr>
    </table>
</body>

</html>